from PIL import Image, ImageDraw

# 加载原始图像
original_image = Image.open("x.png")

# 获取图像尺寸
width, height = original_image.size

# 图像上半部分处理
top_half = original_image.copy()
draw = ImageDraw.Draw(top_half)
for i in range(height // 2):
    for j in range(width):
        draw.point((j, i), fill=(255, 0, 0))
top_half.save("top_half.png")

# 图像左半部分处理
left_half = original_image.copy()
draw = ImageDraw.Draw(left_half)
for i in range(height):
    for j in range(width // 2):
        draw.point((j, i), fill=(255, 0, 0))
left_half.save("left_half.png")

# 图像左上四分之一处理
top_left_quarter = original_image.copy()
draw = ImageDraw.Draw(top_left_quarter)
for i in range(height // 2):
    for j in range(width // 2):
        draw.point((j, i), fill=(255, 0, 0))
top_left_quarter.save("top_left_quarter.png")

# 小区域像素处理（例如，将中心区域的像素值设为白色）
small_region = original_image.copy()
draw = ImageDraw.Draw(small_region)
center_x, center_y = width // 2, height // 2
region_size = 50  # 定义一个小区域的大小
for i in range(center_y - region_size // 2, center_y + region_size // 2):
    for j in range(center_x - region_size // 2, center_x + region_size // 2):
        draw.point((j, i), fill=(255, 255, 255))
small_region.save("small_region.png")

# 指定区域颜色处理（例如，将右下四分之一区域的颜色变为红色）
specified_color = original_image.copy()
draw = ImageDraw.Draw(specified_color)
for i in range(height // 2, height):
    for j in range(width // 2, width):
        draw.point((j, i), fill=(255, 0, 0))
specified_color.save("specified_color.png")

print("所有图像已成功生成并保存。")
